package com.ihrm.demo;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class CreateJwtTest1 {

    /**
     * 通过jwt创建 token
     * @param args
     */
    public static void main(String[] args) {
        // 设置过期时间为1分钟
        long now = System.currentTimeMillis();// 当前时间
        long exp = now + 1000*60;

        JwtBuilder jwtBuilder = Jwts.builder().setId("88").setSubject("李白")
                .setIssuedAt(new Date())
                .signWith(SignatureAlgorithm.HS256, "Awen")
                .setExpiration(new Date(exp))
                .claim("roles","admin")// 自定义claims存储数据
                .claim("logo","logo.png");
        String token = jwtBuilder.compact();
        System.out.println(token);
    }

}
